//
//  OneTextFieldTableViewCell.m
//  IntelligentHousehold
//
//  Created by wmwMAC on 17/6/23.
//  Copyright © 2017年 Cassie. All rights reserved.
//

#import "OneTextFieldTableViewCell.h"

@implementation OneTextFieldTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftTextFiled = [[UITextField alloc] init];
        self.leftTextFiled.font = [UIFont systemFontOfSize:14];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange:) name:UITextFieldTextDidChangeNotification object:_leftTextFiled];
        [self.contentView addSubview:_leftTextFiled];
    }
    
    return self;
}
- (void) textChange:(NSNotification *)noti{
    
    
    if (noti.object == self.leftTextFiled) {
        // 执行代理方法
        NSLog(@"isCurrent");
        
        if (self.leftTextFiled.text.length > 11) {
            self.leftTextFiled.text = [self.leftTextFiled.text substringToIndex:11];
        }
        if ([self.delegate respondsToSelector:@selector(oneTextFieldTableCellPassText:index:)]) {
            [self.delegate oneTextFieldTableCellPassText:self.leftTextFiled.text index:self.tag];
        }
        
    }
    //    NSLog(@"%@",textFiled);
    NSLog(@"%@",self.leftTextFiled.text);
    
//    self.nameIdStr = _leftTextFiled.text;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    _leftTextFiled.frame = CGRectMake(10, 10, ContentWEITH-20, ContentHEIGHT-20);
    
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
